Page({
  data: {
    shop_id: '1234',
    shop_logo: 'https://cdn.mzyun.tech/mzyun.png',
    shop_title: '明志科技旗舰店',
    topImage: 'https://img.alicdn.com/imgextra/i1/376771766/O1CN015Jp8Ea1Ous2Kq8uuh_!!376771766.png',
    follower: 4,
    willShare: 6,
    goodList: [{
      pic_url: 'https://t8.baidu.com/it/u=3571592872,3353494284&fm=79&app=86&f=JPEG?w=1200&h=1290',
      title: '小米手机10',
      price: 1488,
      product_id: 1
    },

    {
      pic_url: 'https://t8.baidu.com/it/u=3571592872,3353494284&fm=79&app=86&f=JPEG?w=1200&h=1290',
      title: '小米手机10',
      price: 1488,
      product_id: 1
    },
    {
      pic_url: 'https://t8.baidu.com/it/u=3571592872,3353494284&fm=79&app=86&f=JPEG?w=1200&h=1290',
      title: '小米手机10',
      price: 1488,
      product_id: 1
    },
    {
      pic_url: 'https://t8.baidu.com/it/u=3571592872,3353494284&fm=79&app=86&f=JPEG?w=1200&h=1290',
      title: '小米手机10',
      price: 1488,
      product_id: 1
    }],
    couponList: [{
      denominations: 100,
      conditions: 200
    },
    {
      denominations: 100,
      conditions: 200
    },
    {
      denominations: 100,
      conditions: 200
    },
    {
      denominations: 100,
      conditions: 200
    }]
  },
  onLoad(query) {
    if (query.main_id) {
      let main_id = query.main_id;
      this.addLog(main_nickName);
      my.alert({
        title: '您已为好友成功助力，自己也赶紧转发参与活动吧！'
      })
    }
    this.loadData()
  },
  goShop() {
    my.tb.navigateToTaobaoPage({
      appCode: 'shop',
      appParams: {
        shopId: this.data.shop_id
      },
      success: (res) => {
      },
      fail: (res) => {
      }
    })
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: '有礼派，分享有礼',
      desc: this.data.shop_title + '店铺促销，邀请您赢好礼',
      path: `/pages/index/index?main_nickName=${getApp().globalData.userInfo.nickName}&shop_id=${getApp().globalData.shop_id}`,
    };
  },
  share() {
    my.showSharePanel();
  },
  async loadData() {
    const { cloud } = getApp();
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/index',
      method: 'GET',
      params: {
        shop_id: getApp().globalData.shop_id
      }
    });
    console.log(res)
    let couponList = [res.coupon];
    this.setData({
      shop_id: res.shop_id,
      shop_title: res.shop_title,
      shop_logo: res.shop_logo,
      topImage: res.topImage,
      timeStamp: res.timeStamp,
      instruction: res.instruction,
      phone: res.phone,
      follower: res.follower,
      willShare: res.willShare,
      goodList: res.good,
      coupon: couponList
    })
  },
  async addLog(main_nickName) {
    const { cloud } = getApp();
    const res = await cloud.application.httpRequest({
      path: '/index.php/index/tb/writelog',
      method: 'POST',
      params: {
        shop_id: getApp().globalData.shop_id,
        main_nickName: main_nickName
      }
    });
    this.goMy();
  },
});
